/**
 * @Title: SysController.java
 * @Package com.lemon.controller.cityRun
 * @Description: (一句话阐述):
 * @author Ran_cc
 * @date 2018年11月8日
 * @version V1.0
 */
package com.lemon.controller.cityRun;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.lemon.conf.MyException;
import com.lemon.conf.redis.RedisUtil;
import com.lemon.controller.BaseController;
import com.lemon.model.cityRun.CrShops;
import com.lemon.model.cityRun.CrSysFeedBook;
import com.lemon.model.cityRun.CrUserTransactionRecord;
import com.lemon.service.cityRun.CrShopsService;
import com.lemon.service.cityRun.CrSysFeedBookService;
import com.lemon.service.cityRun.CrUserTransactionRecordService;
import com.lemon.utils.ReqResult;
import com.lemon.utils.StringUtil;

/**
 * <p>
 * Title: SysController
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author Ran_cc
 * @date 2018年11月8日
 * @版本 V 1.0
 */
@RestController
@RequestMapping("/sys")
public class SysController extends BaseController {

	@Resource
	private CrUserTransactionRecordService tService;
	@Resource
	private CrShopsService shopsService;
	@Resource
	private CrSysFeedBookService fService;

	@RequestMapping(value = "/addSysFeedBack.do" , method = RequestMethod.POST)
	public ReqResult addSysFeedBack(@ModelAttribute CrSysFeedBook feedBook , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {

			feedBook.setStatus(1);
			int list = fService.addFeedBookBySelective(feedBook);
			reqResult.setReturnResult(list);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "修改意见信息异常");
		}
		return reqResult;
	}

	@RequestMapping(value = "/test" , method = RequestMethod.POST)
	public ReqResult test(String data , HttpServletRequest request , HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		System.out.println(data);
		reqResult.setReturnObject(data);
		return reqResult;
	}

	/**
	 * <b>Description:<blockquote>设置系统平台基本信息
	 * </blockquote></b>
	 * 
	 * @Title: addAdminUserInfo
	 * @param user
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年10月18日
	 */
	@RequestMapping(value = "/getSysSet" , method = RequestMethod.POST)
	public ReqResult getShopTranSet(String shopUserId , int type , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			String string = RedisUtil.get(RedisUtil.key_before + "setting");
			if (StringUtil.isNotBlank(string)) {
				JSONObject js2 = ((JSONObject) JSONObject.parse(string)).getJSONObject("sets").getJSONObject("sysSet");
				JSONObject parse = js2;
				log.info(parse.toJSONString());
				CrShops cs = new CrShops();
				cs.setId(shopUserId);
				CrShops shops = shopsService.selectShopAndUserBySel(cs);
				CrUserTransactionRecord t = new CrUserTransactionRecord();
				t.setTranType(3);
				t.setShopUserId(shops.getShopUserId());
				List<CrUserTransactionRecord> list = tService.selectListBySelective(t);
				JSONObject js = new JSONObject();

				if (list.size() > 0) {
					js.put("isFirstYear" , "n");
					if (type == 1) {
						js.put("price" , parse.get("nextYear1"));
					} else if (type == 2) {
						js.put("price" , parse.get("nextYear2"));
					}
				} else {
					js.put("isFirstYear" , "y");
					if (type == 1) {
						js.put("price" , parse.get("firstYear1"));
					} else if (type == 2) {
						js.put("price" , parse.get("firstYear2"));
					}
				}
				js.put("platPhone" , parse.get("platPhone"));
				reqResult.setReturnResult(js);
			}
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "设置系统平台基本信息");
		}
		return reqResult;
	}



}
